package com.parenting.sevice.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.parenting.common.Constant;
import com.parenting.entities.Report;
import com.parenting.entities.Shopper;
import com.parenting.mapper.ReportMapper;
import com.parenting.response.CheckReportVO;
import com.parenting.response.PlazaInfo2ReplyVO;
import com.parenting.response.ReportUserResponse;
import com.parenting.response.ReportVO;
import com.parenting.sevice.PlazaInfoService;
import com.parenting.sevice.ReportService;
import com.parenting.sevice.ShopperService;
import com.parenting.util.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Objects;


/**
 * <p>
 * 投诉 服务实现类
 * </p>
 *
 * @author zcj
 * @since 2021-04-30
 */
@Service
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService {



//    @Override
//    public Page<ReportUserResponse> reportUserList(Integer current, Integer size) {
//        Page<ReportUserResponse> page = new Page<>(current, size);
//        Page<ReportUserResponse> pageList = baseMapper.reportUserList(page);
//        return pageList;
//    }

    @Override
    public Result<ReportVO> reportList(Integer current, Integer size, Integer type) {
        Page<ReportVO> page = new Page<>(current, size);
        Page<ReportVO> pageList = baseMapper.reportList(page, type);
        return Result.buildSuccess(pageList);
    }

    @Override
    public Result<ReportVO> reportUserList(Integer current, Integer size, Integer type) {
        Page<ReportVO> page = new Page<>(current, size);
        Page<ReportVO> pageList = baseMapper.reportUserList(page, type);
        return Result.buildSuccess(pageList);
    }





    @Autowired
    private PlazaInfoService plazaInfoService;
    @Override
    public Result<PlazaInfo2ReplyVO> reportInfo(Integer id) {
        PlazaInfo2ReplyVO plazaInfo2ReplyVO = plazaInfoService.getByPlazaInfo2ReplyVO(id);

        return Result.ok(plazaInfo2ReplyVO);
    }



    @Autowired
    private ShopperService shopperService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result checkReportInfo(CheckReportVO checkReportVO) {
        // 管理员操作 0、拒绝 1、未操作2、删除选中作品3、清楚个人说明4、清空用户标签
        Report report =  getById(checkReportVO.getId());
        if (Objects.isNull(report)) {
            return Result.buildError("审核的举报不存在");
        }
        if (checkReportVO.getOption() == 1) {
            report.setApprovalStatus("3");
        } else if (checkReportVO.getOption() == Constant.OPTION_TWO) {
            report.setApprovalStatus("2");
            plazaInfoService.removeByIds(checkReportVO.getPlazaIdList());
        } else if (checkReportVO.getOption() == Constant.OPTION_THREE) {
            report.setApprovalStatus("2");
            Shopper shopper = shopperService.getById(report.getShopperId());
            if (null!=shopper){
                shopper.setUserDesc("个人说明因违规已被删除");
                shopperService.updateById(shopper);
            }
        } else if (checkReportVO.getOption() == Constant.OPTION_FOUR) {
            report.setApprovalStatus("2");
            Shopper shopper = shopperService.getById(report.getShopperId());
            shopper.setLableOne("违规已删");
            shopper.setLableTwo("违规已删");
            shopper.setLableThree("违规已删");
            shopper.setLableFour("违规已删");
            shopper.setLableFive("违规已删");
            shopper.setLableSix("违规已删");
            shopperService.updateById(shopper);
        }
        report.setOption(checkReportVO.getOption());
        updateById(report);
        return Result.success();
    }
}
